#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N=2e5+10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
int n;
void solve()
{
	cin>>n;
	string s;
	cin>>s;
	int cnt=0;
	for(int i=0,j=s.size()-1;i<j;i++,j--)
	{
		if(i!=j&&s[i]=='0'&&s[j]=='1') cnt+=2;
		else if(i!=j&&s[i]=='1'&&s[j]=='0') cnt+=2;
		else break;
		//else if(i==j) cnt++;
	}

	cout<<s.size()-cnt<<'\n';

	
}

int main()
{
	close();
	int T; cin>>T;
	while (T--) solve();
	return 0;
}